﻿import idv.ben.gc4flash.chart.*;
import idv.ben.gc4flash.dataLine.*;
import idv.ben.gc4flash.encode.*;
import idv.ben.gc4flash.fill.*;
import idv.ben.gc4flash.style.*;
import idv.ben.gc4flash.util.*;
/**
* 散佈圖。<br>
* 參考 Google Chart API：<a href="http://code.google.com/apis/chart/#scatter_plot" target="_blank">http://code.google.com/apis/chart/#scatter_plot</a><br>
*/
class idv.ben.gc4flash.chart.ScatterPlotsChart extends AbstractChart {
	private var gridLinesStyle:GridLinesStyle;
	/**
	* 散佈圖<br>
	* <img src="http://chart.apis.google.com/chart?cht=s&chd=s:984sttvuvkQIBLKNCAIi,DEJPgq0uov17zwopQODS,AFLPTXaflptx159gsDrn&chxt=x,y&chxl=0:|0|2|3|4|5|6|7|8|9|10|1:|0|25|50|75|100&chs=200x125"><br>
	* cht=s
	*/
	public static var CHART_TYPE_ScatterPlotsChart:String = "s";
	/**
	* 建構子
	* @param w 圖檔寬度
	* @param h 圖檔高度
	* @param typ 圖形種類，包括：<br>
	* {@link #CHART_TYPE_ScatterPlotsChart} = "s"<br>
	*/
	function ScatterPlotsChart(w:Number, h:Number, typ:String) {
		super(w, h);
		if(typ==CHART_TYPE_ScatterPlotsChart){
			this.typ = typ
		}else{
			throw new Error("chart type error!!");
		}
		allowParams = Const.CHT_PARAM_Scatter_plot;
	}
	/**
	* 設定散佈圖資料
	* @param values 散佈圖資料的數值陣列，允許個別設定每個資料的 x, y 值，與 size 大小，[{x:Number, y:Number, size:Number}, {x:Number, y:Number, size:Number}, ..., {x:Number, y:Number, size:Number}]
	* @param legend 圖示說明<br>
	* <img src="http://chart.apis.google.com/chart?&cht=lc&chd=t:0,30,60,70,90,95,100|20,30,40,50,60,70,80|10,30,40,45,52&chco=ff0000,00ff00,0000ff&chs=250x150&chdl=First|Second|Third"><br>
	* chdl=First|Second|Third&chco=ff0000,00ff00,0000ff<br>
	*/
	public function setLineXY(values:Array, legend:String):Void {
		var ds_x:ChartDataSet = new ChartDataSet();
		var ds_y:ChartDataSet = new ChartDataSet();
		var ds_size:ChartDataSet = new ChartDataSet();
		var isHasSize:Boolean = false;
		for(var i:Number=0; i<values.length; i++){
			ds_x.addValue(values[i].x);
			ds_y.addValue(values[i].y);
			ds_size.addValue(values[i].size);
			if(values[i].size!=undefined){
				isHasSize = true;
			}
		}
		var dataLine:DataLine = null;
		if(isHasSize){
			dataLine = new LegendDataLine([ds_x, ds_y, ds_size], legend);
		}else{
			dataLine = new LegendDataLine([ds_x, ds_y], legend);
		}
		lines = [{line:dataLine}];
	}
	/**
	* 設定格子樣式
	* @param gridLinesStyle {@link idv.ben.gc4flash.dataLine.GridLinesStyle}
	**/
	public function setGridLinesStyle(gridLinesStyle:GridLinesStyle):Void{
		this.gridLinesStyle = gridLinesStyle;
	}
	/**
	* 取得格子樣式所組成的 URL 參數字串
	* @return URL 參數字串
	**/
	public function getGridLinesStyleChartData():String{
		if(gridLinesStyle!=null){
			return "&chg=" + gridLinesStyle.toChartData();
		}else{
			return "";
		}
	}
}
